﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.esriSystem;

namespace WorldViewSolutions.ArcGISServer.SOE
{
    /// <summary>
    /// Singleton log.
    /// </summary>
    /// <remarks></remarks>
    public sealed class ArcGISLog
    {
        /// <summary>
        /// Allocate ourselves. We have a private constructor, so no one else can.
        /// </summary>
        private static readonly ArcGISLog _instance = new ArcGISLog();

        /// <summary>
        /// 
        /// </summary>
        private ESRI.ArcGIS.esriSystem.ILog _log;


        /// <summary>
        /// Access SiteStructure.Instance to get the singleton object.
        /// Then call methods on that instance.
        /// </summary>
        /// <remarks></remarks>
        private static ArcGISLog Instance
        {
            get { return _instance; }
        }

        /// <summary>
        /// Gets or sets the log.
        /// </summary>
        /// <value>The log.</value>
        /// <remarks></remarks>
        public static ESRI.ArcGIS.esriSystem.ILog Log
        {
            get { return _instance._log; }
            set { _instance._log = value; }
        }


        /// <summary>
        /// This is a private constructor.
        /// </summary>
        /// <remarks></remarks>
        private ArcGISLog()
        {
            // Initialize members, etc. here.
        }


        /// <summary>
        /// Writes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <remarks></remarks>
        public static void Write(string message)
        {
            if (_instance._log != null)
            {
                _instance._log.AddMessage(3, 8000, message);
            }
        }

        /// <summary>
        /// Writes the error.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <remarks></remarks>
        public static void WriteError(string message)
        {
            if (_instance._log != null)
            {
                _instance._log.AddMessage(1, 8000, message);
            }
        }
    }
}